<?php


namespace app\zftpay\controller;


use app\BaseController;
use app\service\xcxService;
use think\facade\Db;

class Common extends BaseController
{
    public function getgroup(){
        $community_id = request()->param('community_id');
        $communityinfo=Db::table("community")->where("community_name",$community_id)->find();
        $community_id=$communityinfo["id"];
        $group = (new xcxService())->groupList($community_id);
        sort($group ,SORT_NATURAL|SORT_STRING|SORT_FLAG_CASE);
        return json($group) ;
    }

    public function getbuilding(){
        $community_id = request()->param('community_id');
        $group = request()->param('group');;
        $building = (new xcxService())->buildingList($group,$community_id);
        sort($building,SORT_NATURAL|SORT_STRING|SORT_FLAG_CASE);
        return json($building);
    }
    public function getunit(){
        $community_id = request()->param('community_id');
        $group = request()->param('group');;
        $building = request()->param('building');
        $unit = (new xcxService())->unitList($building,$group,$community_id);
        sort($unit,SORT_NATURAL|SORT_STRING|SORT_FLAG_CASE);
        return json($unit);
    }
    public function getroom(){
        $community_id = request()->param('community_id');
        $group = request()->param('group');;
        $building = request()->param('building');
        $unit = request()->param('unit');
        $room = (new xcxService())->roomList($unit,$building,$group,$community_id);
        sort($room,SORT_NATURAL|SORT_STRING|SORT_FLAG_CASE);
        return json($room);
    }

    public function getroominfo(){
        $community_id = request()->param('community_id');
        $group = request()->param('group');;
        $building = request()->param('building');
        $unit = request()->param('unit');
        $room = request()->param('room');
        $roominfo=(new xcxService())->getroominfo($community_id,$group,$building,$unit,$room);
        if(empty($roominfo)){
            $arr["errorCode"]="1";
            $arr["errorMsg"]="请选择房屋";
            echo json_encode($arr);
            exit;
        }else{
            $arr["errorCode"]="0";
            $arr["roominfo"]=$roominfo;
            echo json_encode($arr);
            exit;
        }
    }

}